<template>
  <el-card :bordered="false">
    <el-row :gutter="8">
      <el-col :span="5" style="width: 30%">
        <el-menu style="width: 256px" mode="vertical" @select="handleSelect">
          ss
          <el-menu-item v-for="node in nodes" :key="node.nodeId" :title="node.name">
            {{ node.name }}
          </el-menu-item>
        </el-menu>
      </el-col>
      <el-col :span="12" style="width: 60%">
        <div class="table-page-search-wrapper">
          <el-form :form="form">
            <el-form-item>
              <el-alert :closable="false" show-icon title="温馨提示：若流程运行至未分配审批人员的审批节点时，流程将自动中断取消" type="warning"></el-alert>
            </el-form-item>
            <el-form-item label="节点名称">
              <span>{{}}</span>
            </el-form-item>
            <el-form-item label="审批人：">
              <el-checkbox @change="roleChecked=true">角色</el-checkbox>
              <el-checkbox @change="deptChecked=true">部门</el-checkbox>
              <el-checkbox @change="userChecked=true">用户</el-checkbox>
              <el-checkbox >所属部门负责人</el-checkbox>
            </el-form-item>
            <el-form-item label="选择角色：" v-show="roleChecked" prop="role">
              <el-select v-model="form.roles" multiple placeholder="角色">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="选择部门：" v-show="deptChecked">
              <treeselect v-model="form.deptId" style="width: 10vw" :options="deptOptions" :normalizer="normalizer" placeholder="请选择归属机构" />
            </el-form-item>
            <el-form-item label="选择用户：" v-show="userChecked">
              <el-select v-model="form.user" multiple placeholder="用户">
                <el-option
                  v-for="item in userOptions"
                  :key="item.id"
                  :label="item.nickName"
                  :value="item.id"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label=""></el-form-item>
            <el-form-item>
              <el-button>提交</el-button>
              <el-button @click="$router.push({name: 'Process'})">返回</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </el-card>
</template>

<script>
  import { listRole } from '@/api/system/role'  //一定要用大括号接收函数，否则报错
  import { listUser } from '@/api/system/user'
  import { deptTree } from "@/api/system/dept";
  import { getNodeInfo, getNodeList, updateNodeInfo} from "@/api/activiti/node";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    name: 'Node',
    components: { Treeselect },
    data() {
      return {
        roleChecked: false,
        roleOptions: [],
        deptChecked: false,
        deptOptions: [],
        userChecked: false,
        userOptions: [],
        form: {},
        nodes: [],
        mdl: {}
      }
    },
    created() {
      //注意这里接收路由传递参数的“$route”没有“r”的
      const procDefId = this.$route.query.procDefId
      console.log("node parocDefId==="+procDefId)
      getNodeList(procDefId).then(res => {
        this.nodes = res.data.rows.map(n => {
          let icon = ''
          switch (n.type) {
            case 0:
              icon = 'icon-kaishi1'
                  break
            case 2:
              icon = 'icon-jieshu'
                  break
            default:
              icon = 'icon-shen'
          }
          return { name: n.name, nodeId: n.nodeId, icon: icon, type: n.type }
        })
      })
      listRole().then(
        resp => {
          this.roleOptions = resp.data;
        }
      )
      deptTree().then(response => {
        this.deptOptions = response.data;
      });
      listUser().then(res => {
          this.userOptions = res.data;
        })
    },
    methods: {
      /** 转换机构数据结构 */
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.id,
          label: node.name,
          children: node.children
        };
      }
    }
  }
</script>

<style scoped>

</style>
